from django.urls import register_converter


class CateConverter(object):
    regex = r'\w+|(\w+\+\w+)+'

    def to_python(self, value):
        # python + flask + django
        # ['python', 'flask', 'django']
        result = value.split('+')
        print(type(result))
        return result

    def to_url(self, value):
        if isinstance(value, list):
            result = '+'.join(value)
            return str(result)
        else:
            raise RuntimeError('转换分类参数异常，value不是一个list')


register_converter(CateConverter, 'cate')
